package grid;

public final class GridPoint {
	
	public static final int TYPE_NON_GLUE = 0;
	public static final int TYPE_GLUE_X = 1;
	public static final int TYPE_GLUE_Y = 2;
	public static final int TYPE_GLUE_X_Y = 3;
	public final double x,y;
	public final int glue;
	public GridPoint(double x, double y){
		this.x=x;
		this.y=y;
		this.glue = TYPE_NON_GLUE;
	}
	public GridPoint(double x, double y, int glue){
		this.x=x;
		this.y=y;
		this.glue = glue;
	}
	
	public double[] toArray(){
		return new double[]{x,y};
	}
	
	/**
	 * returns a new instance wich respekt the gluing
	 * @param p
	 * @return
	 */
	public GridPoint newInstance(GridPoint p){
		switch (glue) {
		case TYPE_NON_GLUE:
			return p;// new GridPoint(p.x, p.y, TYPE_NON_GLUE);
		case TYPE_GLUE_X:
			return new GridPoint(this.x, p.y, this.glue);
		case TYPE_GLUE_Y:
			return new GridPoint(p.x, this.y, this.glue);
		case TYPE_GLUE_X_Y:
			return new GridPoint(this.x, this.y, this.glue);
		default:
			return null;
		}
		
	}
	@Override
	public String toString() {
		StringBuilder builder = new StringBuilder();
		builder.append("GridPoint [x=").append(x).append(", y=").append(y)
				.append("]");
		return builder.toString();
	}

}
